<template>
  <div>
    <el-row justify="center">
      <h1>销售电影</h1>
    </el-row>
    <el-row>
      <el-col :span="24">
<!--    搜索-->
        <div style="display:flex ;justify-content: space-around">
          <el-form-item label="电影名称:" style="width: 200px">
            <el-input clearable v-model="cutParam.name"/>
          </el-form-item>
          <el-form-item label=" 影院名称:" style="width: 200px">
            <el-input clearable v-model="cutParam.storeName"/>
          </el-form-item>
          <el-form-item label="场次:" style="width: 200px">
            <el-input clearable v-model="cutParam.matches"/>
          </el-form-item>
          <el-form-item label="排号:" style="width: 200px">
            <el-input clearable v-model="cutParam.rowNum"/>
          </el-form-item>
            <el-button type="primary" @click="cutByItem(1)">搜索</el-button>
        </div>

        <el-table :data="cinemaArr" style="width: 100%;margin-bottom: 20px " border stripe>
          <el-table-column prop="name" label="电影名称"/>
          <el-table-column prop="storeName" label="影院名称"/>
          <el-table-column prop="matches" label="场次"/>
          <el-table-column prop="rowNum"  label="坐位号"/>
          <el-table-column label="操作">
            <template #default="scope">
              <el-button @click="buyMovie(scope.row.id)" type="text">购买</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--    分页-->
        <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            background
            layout="prev, pager, next, jumper"
            :total="total"
            @current-change="cutByItem"
        />
       <div style="margin-top: 20px">
         <el-button type="primary" @click="show=true;findAllByUserId()" style="margin-bottom: 20px">我的订单</el-button>
       </div>

        <el-dialog
            v-model="show"
            title="我的订单"
            width="50%"
            style="
        line-height: 40px"
        >
          <el-table
              :data="orderArr"
              border
              style="width:100%">
            <el-table-column
                fixed
                prop="movieName"
                label="电影名称">
            </el-table-column>
            <el-table-column
                prop="matches"
                label="场次"
            >
            </el-table-column>
            <el-table-column
                prop="rowNum"
                label="排号"
            >
            </el-table-column>
            <el-table-column
                prop="seatNum"
                label="坐位号"
            >
            </el-table-column>
          </el-table>
          <template #footer>
    <span class="dialog-footer">
      <el-button type="primary" @click="show = false" style="color: white">确 定</el-button>
    </span>
          </template>
        </el-dialog>

      </el-col>

    </el-row>

  </div>
</template>

<script>
import axios from "axios";
import { ElMessage } from 'element-plus'
export default {
  data() {
    return {
      currentPage: '',
      pageSize: 3,
      cinemaArr: [],
      pageNO: 1,
      total: "",
      cutParam: {},
      user: {},
      show: false,
      orderArr:[]
    }
  },
  methods: {
    //条件查询可购买电影票
    cutByItem(page) {
      // console.log(page)
      this.cutParam.pageNO = page;
      axios.get("/project/sale/cutByItem", {params: this.cutParam})
          .then(reap => {
            this.cinemaArr = reap.data.rows;
            this.total = reap.data.totalCount;
          })
    },
    //购买
    buyMovie(id) {
      axios.get("/project/sale/buyMovie?movieId="+id)
          .then(resp => {
            if (resp.data == "ok") {
              ElMessage({
                message: '购买成功',
                type: 'success',
              })
              this.cutByItem(1)
            }
          })
    },
    //查看我的订单
    findAllByUserId(){
      axios.get("/project/sale/findAllByUserId")
          .then(resp=>{
            this.orderArr=resp.data;
          })
    }

  }, created() {
    this.cutByItem(1);
    this.user = sessionStorage.getItem("loginUser")
  }
}
</script>

<style scoped>

</style>